package o;

import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import android.text.TextUtils;
import com.huawei.appmarket.service.deamon.download.remote.DownloadAgentService;
import com.huawei.hwid.core.constants.HwAccountConstants;
import com.sina.weibo.sdk.api.ImageObject;
import com.sina.weibo.sdk.api.TextObject;
import com.sina.weibo.sdk.api.WebpageObject;
import com.sina.weibo.sdk.api.WeiboMultiMessage;
import com.sina.weibo.sdk.auth.AuthInfo;
import com.sina.weibo.sdk.net.WeiboParameters;
import com.sina.weibo.sdk.network.IRequestService;
import com.sina.weibo.sdk.network.impl.RequestParam.Builder;
import com.sina.weibo.sdk.network.impl.RequestService;
import com.sina.weibo.sdk.network.target.SimpleTarget;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import o.foc.d;

public class fnz extends foc {
    private String ʻ;
    private String ʼ;
    private String ˊ;
    private byte[] ˋ;
    private WeiboMultiMessage ˎ;
    private String ˏ;
    private String ॱॱ;

    public fnz(Context context) {
        this.ॱ = context;
    }

    public fnz(AuthInfo authInfo, fnt o_fnt, String str, int i, String str2, String str3, Context context) {
        super(authInfo, o_fnt, str, i, str2, str3, context);
    }

    public boolean ॱ() {
        if (this.ˋ == null || this.ˋ.length <= 0) {
            return super.ॱ();
        }
        return true;
    }

    public void ˊ(final d dVar) {
        super.ˊ(dVar);
        fnm.ॱ("Share", "ShareWebViewRequestParam.doExtraTask()");
        WeiboParameters weiboParameters = new WeiboParameters(ˋ().ˏ().getAppKey());
        String str = new String(this.ˋ);
        IRequestService instance = RequestService.getInstance();
        Builder builder = new Builder(this.ॱ);
        builder.setShortUrl("https://service.weibo.com/share/mobilesdk_uppic.php");
        builder.addPostParam("img", str);
        builder.addPostParam("appKey", ˋ().ˏ().getAppKey());
        instance.asyncRequest(builder.build(), new SimpleTarget(this) {
            final /* synthetic */ fnz ˊ;

            public void onSuccess(String str) {
                fnm.ॱ("Share", "ShareWebViewRequestParam.doExtraTask().onSuccess(),response = " + str);
                fnp ॱ = fnp.ॱ(str);
                if (ॱ != null && ॱ.ˎ() == 1 && !TextUtils.isEmpty(ॱ.ˊ())) {
                    this.ˊ.ˊ = ॱ.ˊ();
                    if (dVar != null) {
                        dVar.ॱ(this.ˊ.ˊ);
                    }
                } else if (dVar != null) {
                    dVar.ˎ("upload pic fail");
                }
            }

            public void onFailure(Exception exception) {
                fnm.ॱ("Share", "ShareWebViewRequestParam.doExtraTask().onFailure(),e =" + exception.getMessage());
                if (dVar != null) {
                    dVar.ˎ("upload pic fail");
                }
            }
        });
    }

    protected void ˊ(Bundle bundle) {
        if (this.ˎ != null) {
            this.ˎ.toBundle(bundle);
        }
        bundle.putString("token", this.ʻ);
        bundle.putString("packageName", this.ʼ);
        bundle.putString("hashKey", this.ॱॱ);
    }

    protected void ˋ(Bundle bundle) {
        this.ˎ = new WeiboMultiMessage();
        this.ˎ.toObject(bundle);
        this.ʻ = bundle.getString("token");
        this.ʼ = bundle.getString("packageName");
        this.ॱॱ = bundle.getString("hashKey");
        ˎ();
    }

    public String ˊ() {
        String appKey = ˋ().ˏ().getAppKey();
        Uri.Builder buildUpon = Uri.parse("https://service.weibo.com/share/mobilesdk.php").buildUpon();
        buildUpon.appendQueryParameter("title", this.ˏ);
        buildUpon.appendQueryParameter("version", "0041005000");
        if (!TextUtils.isEmpty(appKey)) {
            buildUpon.appendQueryParameter("source", appKey);
        }
        if (!TextUtils.isEmpty(this.ʻ)) {
            buildUpon.appendQueryParameter("access_token", this.ʻ);
        }
        if (this.ॱ != null) {
            Object ˋ = fnr.ˋ(this.ॱ, appKey);
            if (!TextUtils.isEmpty(ˋ)) {
                buildUpon.appendQueryParameter("aid", ˋ);
            }
        }
        if (!TextUtils.isEmpty(this.ʼ)) {
            buildUpon.appendQueryParameter(DownloadAgentService.PACKAGE_NMAE_ARG, this.ʼ);
        }
        if (!TextUtils.isEmpty(this.ॱॱ)) {
            buildUpon.appendQueryParameter("key_hash", this.ॱॱ);
        }
        if (!TextUtils.isEmpty(this.ˊ)) {
            buildUpon.appendQueryParameter("picinfo", this.ˊ);
        }
        buildUpon.appendQueryParameter("luicode", "10000360");
        buildUpon.appendQueryParameter("lfid", "OP_" + appKey);
        return buildUpon.build().toString();
    }

    public void ॱ(WeiboMultiMessage weiboMultiMessage) {
        this.ˎ = weiboMultiMessage;
    }

    public void ˏ(String str) {
        this.ʻ = str;
    }

    public void ˊ(String str) {
        this.ॱॱ = str;
    }

    public void ˋ(String str) {
        this.ʼ = str;
    }

    private void ˎ() {
        StringBuilder stringBuilder = new StringBuilder();
        if (this.ˎ.textObject instanceof TextObject) {
            stringBuilder.append(this.ˎ.textObject.text + HwAccountConstants.BLANK);
        }
        if (!(this.ˎ.mediaObject == null || !(this.ˎ.mediaObject instanceof WebpageObject) || TextUtils.isEmpty(this.ˎ.mediaObject.actionUrl))) {
            stringBuilder.append(this.ˎ.mediaObject.actionUrl);
        }
        if (this.ˎ.imageObject instanceof ImageObject) {
            ImageObject imageObject = this.ˎ.imageObject;
            ˊ(imageObject.imagePath, imageObject.imageData);
        }
        this.ˏ = stringBuilder.toString();
    }

    private void ˊ(String str, byte[] bArr) {
        FileInputStream fileInputStream;
        Throwable th;
        try {
            if (!TextUtils.isEmpty(str)) {
                File file = new File(str);
                if (file.exists() && file.canRead() && file.length() > 0) {
                    byte[] bArr2 = new byte[((int) file.length())];
                    FileInputStream fileInputStream2 = null;
                    try {
                        fileInputStream = new FileInputStream(file);
                        try {
                            fileInputStream.read(bArr2);
                            this.ˋ = fng.ˏ(bArr2);
                            if (fileInputStream != null) {
                                try {
                                    fileInputStream.close();
                                    return;
                                } catch (Exception e) {
                                    return;
                                }
                            }
                            return;
                        } catch (IOException e2) {
                            if (fileInputStream != null) {
                                try {
                                    fileInputStream.close();
                                } catch (Exception e3) {
                                }
                            }
                            if (bArr != null) {
                            }
                            return;
                        } catch (Throwable th2) {
                            Throwable th3 = th2;
                            fileInputStream2 = fileInputStream;
                            th = th3;
                            if (fileInputStream2 != null) {
                                try {
                                    fileInputStream2.close();
                                } catch (Exception e4) {
                                }
                            }
                            throw th;
                        }
                    } catch (IOException e5) {
                        fileInputStream = null;
                        if (fileInputStream != null) {
                            fileInputStream.close();
                        }
                        if (bArr != null) {
                            return;
                        }
                    } catch (Throwable th4) {
                        th = th4;
                        if (fileInputStream2 != null) {
                            fileInputStream2.close();
                        }
                        throw th;
                    }
                }
            }
        } catch (SecurityException e6) {
        }
        if (bArr != null && bArr.length > 0) {
            this.ˋ = fng.ˏ(bArr);
        }
    }
}
